package demo150;

import java.util.HashMap;
import java.util.Map;

public class majorityElement {
    public int majorityElement(int[] nums) {
        int ret = 0;
        int n = nums.length;
        Map<Integer,Integer> hash = new HashMap<>();
        for(int i = 0;i < n;i++) {
            hash.put(nums[i],hash.getOrDefault(nums[i],0)+1);
            int tem = hash.get(nums[i]);
            if( tem> n/2){
                ret = nums[i];
                break;
            }
        }
        return ret;
    }
}
